#ifndef AT_NETWORK_HTTP_h
#define AT_NETWORK_HTTP_h

#include "AtNetworkDevice.h"

/** HTTP 回调函数 */
typedef size_t (*HttpCallback)(size_t length, char *body);

class AtNetworkHttp {
  protected:
    AtNetworkDevice *device;

  public:
    AtNetworkHttp(AtNetworkDevice *device) {
      this->device = device;
    };

    /**
     * 发起GET请求(需要手动调用lock)
     * @param fun 请求回调接口
     * @param 请求地址
     * @param timeout 超时时长
     */
    virtual size_t get(HttpCallback fun, char *url, uint32_t timeout = 10000) = 0;

    /**
     * 发送POST请求(需要手动调用lock)
     * @param fun     回调函数
     * @param url     请求地址
     * @param body    请求内容
     * @param timeout 超时时长
     *
     */
    virtual size_t post(HttpCallback fun, char *url, char *body, uint32_t timeout = 10000) = 0;

  protected:
    inline int wait(uint32_t timeout, AtKey key) {
      return this->device->wait(timeout, key);
    }
};

#endif